import { ResponseData } from "@/types/common/response";
import { http } from "@/utils/http";
import {
  OrderPersonnelDTO,
  AddOrderPersonnelRequest,
  BatchAddOrderPersonnelRequest
} from "@/types/attendance/order/personnelRelation";

/**
 * 获取订单关联人员列表
 * @param orderId 订单ID
 * @returns 人员列表
 */
export function getOrderPersonnelList(orderId: number): Promise<ResponseData<OrderPersonnelDTO[]>> {
  return http.get<any, ResponseData<OrderPersonnelDTO[]>>(
    `/attendance/order/personnel/list/${orderId}`
  );
}

/**
 * 添加订单人员关联
 * @param data 添加命令
 * @returns 操作结果
 */
export function addOrderPersonnel(data: AddOrderPersonnelRequest): Promise<ResponseData<void>> {
  return http.post<any, ResponseData<void>>("/attendance/order/personnel", { data });
}

/**
 * 批量添加订单人员关联
 * @param data 批量添加命令
 * @returns 操作结果
 */
export function batchAddOrderPersonnel(
  data: BatchAddOrderPersonnelRequest
): Promise<ResponseData<void>> {
  return http.post<any, ResponseData<void>>("/attendance/order/personnel/batch", { data });
}

/**
 * 解除订单人员关联
 * @param id 关联ID
 * @returns 操作结果
 */
export function removeOrderPersonnel(id: number): Promise<ResponseData<void>> {
  return http.request("delete", `/attendance/order/personnel/${id}`);
}

/**
 * 获取可选人员列表
 * @param orderId 订单ID
 * @param query 查询参数
 * @returns 人员列表
 */
export function getAvailablePersonnelList(
  orderId: number,
  query?: {
    pageNum?: number;
    pageSize?: number;
    personnelName?: string;
    personnelCode?: string;
  }
): Promise<
  ResponseData<{
    rows: Array<{
      personnelId: number;
      personnelCode: string;
      personnelName: string;
      supplierId: number;
      supplierName: string;
      level: string;
      levelName: string;
      monthlyRate: number;
    }>;
    total: number;
  }>
> {
  return http.get<
    any,
    ResponseData<{
      rows: Array<{
        personnelId: number;
        personnelCode: string;
        personnelName: string;
        supplierId: number;
        supplierName: string;
        level: string;
        levelName: string;
        monthlyRate: number;
      }>;
      total: number;
    }>
  >(`/attendance/order/personnel/available/${orderId}`, { params: query });
}
